package com.neuedu.web;

import com.neuedu.pojo.AdminTable;
import com.neuedu.pojo.Result;
import com.neuedu.service.AdminTableService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/adminTable")
@Tag(name="管理员管理")
public class AdminTableController {
    @Resource
    private AdminTableService adminTableService;

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/id")
    public Result<AdminTable> getAdminTableById(Integer id) {
        return this.adminTableService.getAdminTableById(id);
    }

    /**
     * 分页和条件查询
     * @param currentPage
     * @param pageSize
     * @param phone
     * @return
     */
    @GetMapping("/getAdminTables")
    public Result<List<AdminTable>> getAdminTables(
            @RequestParam(name = "currentPage",defaultValue = "1")Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
            @RequestParam(name = "phone",defaultValue = "")String phone,
            @RequestParam(name = "adminName",defaultValue = "")String adminName) {
        return this.adminTableService.getAdminTables(currentPage,pageSize,phone,adminName);
    }
    /**
     * 添加
     */
    @PostMapping("/addAdminTable")
    public Result<Void> addAdminTable(@RequestBody AdminTable adminTable) {
        return this.adminTableService.addAdminTable(adminTable);
    }
    /**
     * 修改
     */
    @PutMapping("/updateAdminTable")
    public Result<Void> updateAdminTable(@RequestBody AdminTable adminTable) {
        return this.adminTableService.updateAdminTable(adminTable);
    }
    /**
     * 删除
     */
    @DeleteMapping("deleteAdmin/{id}")
    public Result<Void> deleteAdminTable(@PathVariable("id") Integer id) {
        return this.adminTableService.deleteAdminTable(id);
    }
}
